package com.tz.colawallet.ui.adapter;

import android.content.Context;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.tz.colawallet.R;
import com.tz.colawallet.basecode.comm.RetrofitHelpNew;
import com.tz.colawallet.bean.Recommand;
import com.tz.colawallet.util.CommonUtil;

/**
 * @author tz
 * @创建日期 2017.12.11
 */

public class MainFirstAdapter extends BaseQuickAdapter<Recommand, BaseViewHolder> {
    private Context context;
    private OnListener onListener;

    public MainFirstAdapter(int layoutResId, Context context) {
        super(layoutResId);
        this.context = context;
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void convert(final BaseViewHolder helper, Recommand item) {
        ImageView photo = helper.getView(R.id.product_img);
        Glide.with(context).load(item.getImg()).into(photo);
        helper.setText(R.id.product_title, item.getCname())
                .setText(R.id.product_apply_times, item.getApplynum() + "人已申请")
                .setText(R.id.product_money, item.getMoney())
                .setText(R.id.cond, item.getCond())
                .setText(R.id.loan_time, item.getLoantime());
        Button applyBtn = helper.getView(R.id.apply_btn);
        applyBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onListener.onListener(helper.getPosition());
            }
        });
    }

    public interface OnListener {
        void onListener(int position);
    }

    public void setOnListener(OnListener onListener) {
        this.onListener = onListener;
    }
}
